Using Morph resources

Use Morph resource to change one shape into another through a seamless transition. Kanzi uses shaders to enable morphing.

To morph between shapes in Kanzi you need to:

When you create 3D models in your third-party tool between which you want to morph, first create the base model and then from that model shape the model to which you want to morph. When creating the models keep in mind:

Morphing meshes

To morph meshes:

  1. Create the material type that Kanzi can use to morph between meshes:
    1. In the Library right-click Materials and Textures and select Load Material Type From Disk.
    2. Load the Phong material type and rename it to PhongMorph.
    3. In the Library > Materials and Textures > Material Types > PhongMorph open the vertex shader and replace
      attribute vec3 kzPosition;
      attribute vec3 kzNormal;

      with

      attribute vec3 kzMorphTarget0Position;
      attribute vec3 kzMorphTarget1Position;
      attribute vec3 kzMorphTarget0Normal;
      attribute vec3 kzMorphTarget1Normal;

      To morph between more than two meshes, add as many kzMorphTargetPosition and kzMorphTargetNormal attributes as you have meshes between which you want to morph.

    4. In the PhongMorph material type vertext shader add
      uniform mediump float kzMorphWeights[2];

      To morph between more than two meshes, set the kzMorphWeights to the number of meshes between which you want to morph.

    5. In the PhongMorph material type vertext shader in the main() function instead of
      vec4 positionWorld = kzWorldMatrix * vec4(kzPosition.xyz, 1.0);

      use

      vec3 position = kzMorphTarget0Position * kzMorphWeights[0] + kzMorphTarget1Position * kzMorphWeights[1];
      vec4 positionWorld = kzWorldMatrix * vec4(position.xyz, 1.0);
      vec3 V = normalize(positionWorld.xyz - kzCameraPosition);
      vec3 normal =
      	normalize(
      		(kzMorphTarget0Normal * kzMorphWeights[0]) +
      		(kzMorphTarget1Normal * kzMorphWeights[1])
      	);

      To morph between more than two meshes, adjust the kzMorphTargetPosition, kzMorphWeights, and kzMorphTargetNormal values accordingly.

    6. In the PhongMorph material type vertext shader in the main() function replace
      vec4 N = kzNormalMatrix * vec4(kzNormal, 1.0);
      vNormal = N.xyz;
      gl_Position = kzProjectionCameraWorldMatrix * vec4(kzPosition.xyz, 1.0);

      with

      vec4 N = kzNormalMatrix * vec4(kzNormal, 1.0);
      vNormal = N.xyz;
      gl_Position = kzProjectionCameraWorldMatrix * vec4(position.xyz, 1.0);
  2. Create a material that uses the PhongMorph material type:
    1. In the Library press Alt and right-click Materials and Textures, and select Material.
    2. In the Properties set the Material Type property to PhongMorph.
    3. (Optional) Adjust the material properties. For example, to change the base color of the material, adjust the Ambient Color property.
  3. In the Assets click Import Assets and import the 3D model which contains the meshes between which you want to morph.
    After Kanzi Studio imports the 3D model to your project, it creates the meshes from the 3D model, and a Morph resource that uses the imported meshes. You can find these resources in the Library > Meshes.
    Note If Kanzi Studio imports extra morph target shapes without polygon data, in the Library > Meshes select the Morph and in the Properties set the Morph Targets property to point to the meshes that include the polygon data.
  4. In the Library select the imported meshes and in the Properties set the Cluster Material property to the material that uses the PhongMorph material type.
  5. Include the morph in your application:
    1. In the Project press Alt and right-click the node where you want to place the morph and select Model.
    2. In the Properties set the Mesh property to the Morph resource you want to use.
    3. To adjust the level of morphing in the Library > Meshes select the Morph resource and in the Properties in the Morph Targets property adjust the Weight property to control the shape of the morph. For example, to animate the morphing, make the animation target the <MorphWeight>[n] property of the Morph resource, where n is the mesh in the Morph the weight of which you want to change.

Adding meshes to a Morph

To add meshes to a Morph:

  1. In the Library press Alt and right-click Meshes and select Morph.
  2. In the Properties in the Morph Targets property:
    1. Use the drop-down menu to select the mesh from which you want to morph.
    2. Adjust the Weight property.
      The higher the value, the closer the morph takes the shape of that mesh. Keep in mind that for the morph to make sense the sum of the Weight property values for all meshes must be 1.
  3. In the Properties in the Morph Targets property click Add to add another mesh to which you want to morph, and repeat the previous step to select the mesh and the weight you want to use for that mesh.

See also

3D content

Importing 3D content

Preparing 3D assets in third-party tools

Editing shaders

Using meshes